package com.zhang.crm.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.zhang.crm.CrmApplication;
import com.zhang.crm.pojo.TDicValue;
import com.zhang.crm.result.DicEnum;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 意向状态转换器
 */
public class IntentionStateConverter implements Converter<Object> {

    /**
     * Excel to Java
     * @param cellData  单元格数据
     * @param contentProperty
     * @param globalConfiguration
     * @return
     * @throws Exception
     */
    @Override
    public Object convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String data = cellData.getStringValue();
        if (StringUtils.hasText(data)){
            List<TDicValue> dicValueList = CrmApplication.dicCacheMap.get(DicEnum.INTENTIONSTATE.getDicName());
            for (TDicValue tDicValue : dicValueList) {
                if (data.equals(tDicValue.getTypeValue())){
                    return tDicValue.getId();
                }
            }
            
        }
        return -1;

    }

    /**
     * Java to Excel
     * @param value
     * @param contentProperty
     * @param globalConfiguration
     * @return
     * @throws Exception
     */
   /* @Override
    public WriteCellData<?> convertToExcelData(Object value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return Converter.super.convertToExcelData(value, contentProperty, globalConfiguration);
    }*/
}
